package com.example.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.common.utils.R;
import com.example.system.entity.Order;
import com.example.system.service.IOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 王鹤蒲
 * @since 2024-02-03
 */
@Api(tags = "订单信息API",description="提供订单信息相关的 REST API")
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private IOrderService iOrderService;

    @ApiOperation(value = "", notes = "")
    @RequestMapping(value="/createOrder",method = RequestMethod.POST)
    @ResponseBody
    public R createOrder(@RequestBody Order order) throws ClassNotFoundException {
        return iOrderService.createOrder(order);
    }

    @ApiOperation(value = "", notes = "")
    @RequestMapping(value="/selectAll",method=RequestMethod.GET)
    @ResponseBody
    public R selectAll(@RequestParam int currentPage, @RequestParam int pageSize, @RequestParam(defaultValue = "")String orderNo, @RequestParam(defaultValue = "")String status,@RequestParam(defaultValue = "") String type,@RequestParam(defaultValue = "") String createBy, @RequestParam(defaultValue = "") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate createDate) {
        return iOrderService.selectAll(currentPage,pageSize,orderNo,status,type,createBy,createDate);
    }

    @ApiOperation(value = "", notes = "")
    @RequestMapping(value="/selectOrderDetail/{orderNo}",method=RequestMethod.GET)
    @ResponseBody
    public R selectOrderDetail(@PathVariable("orderNo") String orderNo) {
        return iOrderService.selectOrderDetail(orderNo);
    }

    @ApiOperation(value = "", notes = "")
    @RequestMapping(value="/cancel/{orderNo}",method=RequestMethod.GET)
    @ResponseBody
    public R cancelOrder(@PathVariable("orderNo") String orderNo) {
        return iOrderService.cancelOrder(orderNo);
    }

    @ApiOperation(value = "", notes = "")
    @RequestMapping(value="/cancelBatch",method=RequestMethod.POST)
    @ResponseBody
    public R cancelBatch(@RequestBody String [] orderNoList) {
        return iOrderService.cancelBatch(orderNoList);
    }

    @ApiOperation(value = "", notes = "")
    @RequestMapping(value="/delete/{orderNo}",method=RequestMethod.GET)
    @ResponseBody
    public R deletelOrder(@PathVariable("orderNo") String orderNo) {
        return iOrderService.deletelOrder(orderNo);
    }

    @ApiOperation(value = "", notes = "")
    @RequestMapping(value="/deleteBatch",method=RequestMethod.POST)
    @ResponseBody
    public R deleteBatch(@RequestBody String [] orderNoList) {
        return iOrderService.deleteBatch(orderNoList);
    }


    @ApiOperation(value = "", notes = "")
    @RequestMapping(value="/findOrderDetailListByPage",method=RequestMethod.GET)
    @ResponseBody
    public R findOrderDetailListByPage(@RequestParam int currentPage,@RequestParam int pageSize, @RequestParam Integer userId, @RequestParam String workDate, @RequestParam(defaultValue = "") String status) {
       return iOrderService.findOrderDetailListByPage(currentPage,pageSize,userId,workDate,status);
    }


    @ApiOperation(value = "", notes = "")
    @RequestMapping(value="/findPatientOrderList",method=RequestMethod.GET)
    @ResponseBody
    public R findPatientOrderList(@RequestParam int currentPage,@RequestParam int pageSize,@RequestParam Integer userId,@RequestParam(defaultValue = "") String orderDate,@RequestParam(defaultValue = "") String status) {
        return iOrderService.findPatientOrderList(currentPage, pageSize, userId, orderDate, status);
    }

    @ApiOperation(value = "", notes = "")
    @RequestMapping(value="/serviceEvaluation",method=RequestMethod.GET)
    @ResponseBody
    public R serviceEvaluation(@RequestParam String orderNo,@RequestParam Integer rate,@RequestParam(defaultValue = "") String feedback) {
        return iOrderService.serviceEvaluation(orderNo,rate,feedback);
    }
}

